<%@page import="com.wanmait.hotelManage.vo.Pager"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="com.wanmait.hotelManage.vo.Car"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
    String path=request.getContextPath();
    List<Car>cars=(List<Car>)request.getAttribute("cars");
    %>
<jsp:include page="/manage/inc/header.jsp"></jsp:include>
   <jsp:include page="/manage/inc/menu.jsp"></jsp:include>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<%=path%>/manage/index.jsp">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">车辆管理</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a id="batchInsert" href="<%=path%>/manage/car/insert.jsp"><i class="icon-font"></i>新增车辆</a>
                         <a id="batchDel" href="<%=path%>/manage/CarServlet?action=update"><i class="icon-font"></i>修改价钱</a>
                        <!-- <span id="roomtypeid">
                                     <select name="textid" id="textid" class="required">
                                    <option value="1">空闲</option>
                                    <option value="2">正在使用</option>
                                </select>
                     <input class="btn btn-primary btn6 mr10" id="roomtype" value="搜索" type="button"><span id="spanroomtype"></span>
                     </span> -->
                    </div> 
                </div>
                <div class="result-content">
                <div id="bbb">
                    <table class="result-tab" width="100%">
                        <tr>
                            <!-- <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th> -->
                            <th>序号</th>
                            <th>ID</th>
                            <th>车牌号</th>
                            <th>是否正在使用</th>
                            <th>价钱</th>
                            <th>时间</th>
                            <th>操作</th>
                        </tr>
                        <%
                        if(cars!=null){
                        	DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        	for(int i=0;i<cars.size();i++){
                        		Car car=cars.get(i);
                        		String inputTime=df.format(car.getInputTime());
                        		%>
                        		 <tr id="tr<%=car.getId()%>">
                           <!--  <td class="tc"><input name="id[]" value="59" type="checkbox"></td> -->
                            <td><%=i+1 %></td>
                            <td><%=car.getId() %></td>
                            <td><%=car.getNumber() %></td>
                            <td class="checkin"><%=car.getCheck() %></td>
                            <td><%=car.getPrice() %></td>
                            <td><%=inputTime %></td>
                            <td>
                               <%--  <a class="link-update" href="<%=path%>/manage/CarServlet?action=update&id=<%=car.getId()%>">修改</a> --%>
                                 <a id="de<%=car.getId() %>" class="link-del" href="#">删除</a> 
                            </td>
                        </tr>
                        		<%
                        	}
                        }
                        %>
                    </table>
                    <div class="qwe">
                    <%
                    Pager pager=(Pager)request.getAttribute("pager");
                    if(pager!=null){
                    	 int start= 1;
                         int end =pager.getPageCount();
                         if(pager.getPageCount()>5){
                        	 start=pager.getPageNo()-2<1?1:pager.getPageNo()-2;
                        	 end=start+4;
                        	 if(end>pager.getPageCount()){
                        		 end=pager.getPageCount();
                        		 start=end-4;
                        	 }
                         }
                         %>
                         [<a class="ok" href="javascript:void(0)">上一页</a>]
                         <%
                    	for(int i=start;i<=end;i++){
                    		%>
                    		[<a class="number" href="javascript:void(0)"><%=i %></a>]
                    		<%
                    	}
                         %>
                         [<a class="no" href="javascript:void(0)">下一页</a>]
                         <%
                    }
                    %>
                    </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
  <jsp:include page="/manage/inc/footer.jsp"></jsp:include>
  <style>
  .qwe{
text-align:center;
}
#roomtypeid{
margin-left:100px;
}
  </style>
  <script>
  $(function(){
	  $(".checkin").each(function(){
			var check=$(this).html();
			
			if(check=="false"){
				$(this).html("空闲");
			}else if(check=="true"){
				$(this).html("正在使用");
			} 
		})
		/* $(".enable").each(function(){
			var check=$(this).html();
			
			if(check=="false"){
				$(this).html("不可用");
			}else if(check=="true"){
				$(this).html("可用");
			} 
		}) */
		 $("#bbb").on("click",".link-del",function(){
		if(!window.confirm("你确定要删除吗")){
			return false;
		}
		var id=$(this).attr("id").substring(2);
		$.get("<%=path%>/manage/CarServlet?action=del",
				{id:id},
				function(){
					$("#tr"+id).remove();
				}
				)
	}) 
	$(".no").click(function(){
							/* $(".number").css("color","black");
							$(this).css("color","red"); */
							var content=<%=pager.getPageNo()%>;
							if(content<<%=pager.getPageCount()%>){
								content++;
							}
							$.ajax({
								url:"<%=path%>/manage/CarServlet?action=inittwo",
									data:{pageNo:content},
										success:function(msg){
											$("#bbb").html(msg);
										}
							})
						})
	$(".ok").click(function(){
		/* $(".number").css("color","black");
		$(this).css("color","red"); */
		var content=<%=pager.getPageNo()%>;
		if(content>1){
			content--;
		}
		$.ajax({
			url:"<%=path%>/manage/CarServlet?action=inittwo",
				data:{pageNo:content},
					success:function(msg){
						$("#bbb").html(msg);
					}
		})
	})
	$(".number").click(function(){
		var content=$(this).html();
		$.ajax({
			url:"<%=path%>/manage/CarServlet?action=inittwo",
			data:{pageNo:content},
			success:function(msg){
				$("#bbb").html(msg);
			}
		})
		
	})
	<%-- $("#roomtype").click(function(){
		var text=$("#textid").val();
		/* if(text.length==0){
			$("#spanroomtype").html("不能为空");
			return false;
		}else{
			$("#spanroomtype").html(" "); */
			$.ajax({
				url:"<%=path%>/manage/CarServlet?action=search",
					data:{text:text},
						success:function(msg){
							$("#bbb").html(msg);
						}
			})
		}) --%>
		})
  </script>